package com.exartisan.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.exartisan.bean.GalleryContent;
import com.exartisan.thanhdoanhn.R;
import com.exartisan.thanhdoanhn.VideoActivity;
import com.loopj.android.image.SmartImageView;


public class VideoHolderPagerAdapter extends PagerAdapter {
	Context context;
	ArrayList<GalleryContent> content;
	LayoutInflater inflater;


	public VideoHolderPagerAdapter(Context context, ArrayList<GalleryContent> videoData) {
		this.context = context;
		this.content = videoData;
	}

	@Override
	public int getCount() {
		return content.size();
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		return view == ((RelativeLayout) object);
	}

	@Override
	public Object instantiateItem(ViewGroup container, final int position) {
		// Declare Variables
		SmartImageView smartImg;
		ImageView videoSymbol;
		inflater = (LayoutInflater) context
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View itemView = inflater.inflate(R.layout.viewpager_video_item, container,
				false);

		// viewpager_item.xml
		 smartImg = (SmartImageView) itemView.findViewById(R.id.image);
		 videoSymbol = (ImageView) itemView.findViewById(R.id.videoSymbol);
		 
		// Set data
		smartImg.setImageUrl(content.get(position).getThumbUrl());
		itemView.setId(position);
		
		videoSymbol.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(context, VideoActivity.class);
				intent.putExtra("data", content.get(position));
				context.startActivity(intent);
			}
		});

		// Add viewpager_item.xml to ViewPager
		((ViewPager) container).addView(itemView);

		return itemView;

	}

	@Override
	public void destroyItem(View container, int position, Object object) {
		// TODO Auto-generated method stub
		((ViewPager) container).removeView((RelativeLayout) object);
	}

}
